<template>
  <div class="header">
    <div class="title">
      <div class="iconfont">&#xe611; 购物车</div>
    </div>
    <div class="delete" @click="deleteGoodsFromCart">删除</div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'CartHeader',
  computed: {
    ...mapState(['cartGoods'])
  },
  methods: {
    deleteGoodsFromCart () {
      if (this.cartGoods.some(val => val.isInCart)) {
        this.$confirm('您是否要删除已选中商品', '', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: '',
          center: true
        }).then(() => {
          this.$store.commit('deleteGoodsFromCart')
        }).catch(() => {})
      } else {
        this.$message.info('您未选中任何商品')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.header {
  display: flex;
  position: fixed;
  top: 0;
  width: 15rem;
  line-height: 1.6rem;
  text-align: center;
  background-color: #fff;
  z-index: 99;
  .title {
    display: inline-block;
    flex: 1;
    font-size: 0.4rem;
    margin-left: 2.4rem;
  }
  .delete {
    display: inline-block;
    width: 2.4rem;
    font-size: .56rem;
  }
}
</style>
